#!/usr/bin python3
# -*- coding:UTF-8 -*-
# Author: nigo
import pandas as pd
import plotly.graph_objects as go

# 数据
df = pd.DataFrame([
    ["2019-01", 677.59 ],
    ["2019-02", 670.82 ],
    ["2019-03", 690.02 ],
    ["2019-04", 689.96 ],
    ["2019-05", 701.50 ],
    ["2019-06", 705.37 ],
    ["2019-07", 681.74 ],
    ["2019-08", 649.31 ],
    ["2019-09", 629.75 ],
    ["2019-10", 623.21 ],
    ["2019-11", 630.22 ],
    ["2019-12", 621.71 ],
],columns=[ "月份" , "平均消费额" ])
avg = df['平均消费额'].mean()
# 轨迹（线）
line = go.Scatter(x=df['月份'],y=df['平均消费额'],name='月平均消费额')
line_avg = go.Scatter(x=df['月份'],y=[avg]*len(df),name='年平均消费额')
# 画布
fig = go.Figure([line,line_avg])
# 更改样式
fig.update_layout(title='订单平均消费额分析',yaxis_range=[500,750],
                  # xaxis_tickformat='%Y-%m'
                  xaxis_tickmode='array',
                  xaxis_tickvals=df['月份'],
                  xaxis_ticktext=['一','二','三','四','五','六','七','八','九','十','十一','十二'],
                 )
# 显示画布
fig.show()
